<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<jsp:useBean id="event" scope="session" class="com.asaga.tools.Event_DBImpl" />
<jsp:useBean id="userProfile" scope="session" class="com.asaga.tools.SystemClient_DBImpl" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<% 
String username = (String)session.getAttribute("username");
if(username==null){
    response.sendRedirect("login.jsp?message=Please log in again.");
}%>

<html>
    <%@ include file="header.jsp" %>
<body>
    <div class="container">
        <%@ include file="topNav.jsp" %>
        <%@ include file="leftside.jsp" %>
        <%@ include file="rightside.jsp" %>
        <h2>
            WELCOME, <%=username%>!(<a href="AutismSiteMasterController?action=logoff">Logout</a>)
        </h2>
        <p id="warning"><jsp:getProperty name="event" property="warningMessage" />
        </p>
        <!-- Main page content -->
        <div class="myEvents">
            <% ResultSet myEvents = event.getEventsByPersonId(userProfile.getId());
            %>
            <h4 class="heading">My Created Events</h4>
            <ul>
                <%if(myEvents.next()){
                    myEvents.first();
                    while(myEvents.next()){
                %>
                <li class="eventListing">
                    <span class="eventTitle">
                      <%=myEvents.getString("title")%>    
                    </span><br />
                      Date:<%=myEvents.getDate("startDate")%> thru
                           <%=myEvents.getDate("endDate")%><br />
                      Time:<%=myEvents.getTime("startTime")%> - <%=myEvents.getTime("endTime")%>
                </li>
               <%       }
                    }
                    else{
               %>
                <span class="eventTitle">No events created </span>
                <%}%>
            </ul>
            <span class="eventDisplay"><a href="AutismSiteMasterController?action=addEventForm">Add an Event</a></span>
            <span class="eventDisplay"><a href="AutismSiteMasterController?action=listEvents">List My Events</a></span>
        </div>
        <div class="myEvents">
            <% if(!userProfile.getState().equals(null)){
                ResultSet areaEvents = event.getEventsByState(userProfile.getState());
            %>
            <h4 class="heading">Events In Your Area</h3>
            <ul>
                <%if(areaEvents.next()){
                    areaEvents.first();
                    while(areaEvents.next()){
                %>
                <li class="eventListing">
                    <span class="eventTitle">
                      <%=areaEvents.getString("event_title")%>    
                    </span><br />
                      Date:<%=areaEvents.getDate("startDate")%> thru
                           <%=areaEvents.getDate("endDate")%><br />
                      Description:<%=areaEvents.getString("description")%>
                </li>
               <%       }
                    }
                 }
                    else{
               %>
                <span class="eventListing">No Events in your area at this time.
                    <%if(userProfile.getState().equals(null)){%>
                    You should add your address to your profile to get events in your area.
                    <%}
                    }%>
                </span>
            </ul>
        </div>          
       <%@ include file="footer.jsp" %> 
    </div>
</body>
</html>
